﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Control;

namespace PJRScrum
{
    public partial class Form1 : Form
    {
        #region Knoppen en Acties
        public Form1()
        {
            InitializeComponent();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
        {
            schuiven((-vScrollBar1.Value), Plattegrond.Left);
        }

        private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
        {
            schuiven(Plattegrond.Top, (-hScrollBar1.Value));
        }

        private void btnZoomIn_Click(object sender, EventArgs e)
        {
            zoompercentage += 10;
            Zoom();
        }

        private void btnZoomOut_Click(object sender, EventArgs e)
        {
            if (zoompercentage > 10) { zoompercentage -= 10; }
            Zoom();
        }

        private void btnImport_Click(object sender, EventArgs e)
        {
            //ImportGUI importGui = new ImportGUI();
            //importGui.ShowDialog();
            zoompercentage = 100;
            //Haal info van winkel op via interface
            //Zet de afbeelding neer in de picturebox
        }

        #endregion

        #region eigen Methodes
        /// <summary>
        /// Regelt het verschuiven van de plattegrond
        /// </summary>
        /// <param name="Top">Hoeveel er vanuit de top verschoven moet worden</param>
        /// <param name="Left">Hoeveel er vanuit de linker zijde verschoven moet worden</param>
        private void schuiven(int Top, int Left)
        {
            Plattegrond.Top = Top;
            Plattegrond.Left = Left;
        }

        /// <summary>
        /// Zoomt in met de algemene zoomfactor
        /// </summary>
        private void Zoom()
        {
            if (achtergrond != null)
            {
                Size formaat = new Size((int)((zoompercentage / 100) * achtergrond.Width), (int)((zoompercentage / 100) * achtergrond.Height));
                Bitmap zoombmp = new Bitmap(achtergrond, formaat);
                int hPercentage = hScrollBar1.Maximum;
                int vPercentage = vScrollBar1.Maximum;
                PlattegrondTonen(zoombmp);
                vScrollBar1.Value = (vScrollBar1.Value * vScrollBar1.Maximum) / vPercentage;
                hScrollBar1.Value = (hScrollBar1.Value * hScrollBar1.Maximum) / hPercentage;
                schuiven(-vScrollBar1.Value, -hScrollBar1.Value);
            }
        }

        /// <summary>
        /// Toont de gegeven afbeelding op het plattegrond vlak.
        /// </summary>
        /// <param name="image">De plattergrond</param>
        private void PlattegrondTonen(Image image)
        {
            btnZoomIn.Visible = true;
            btnZoomOut.Visible = true;
            if (panel1.Height <= image.Height)
            {
                vScrollBar1.Maximum = image.Height - panel1.Height;
                vScrollBar1.Visible = true;
            }
            else { vScrollBar1.Visible = false; }
            if (panel1.Width <= image.Width)
            {
                hScrollBar1.Maximum = image.Width - panel1.Width;
                hScrollBar1.Visible = true;
            }
            else { hScrollBar1.Visible = false; }
            Plattegrond.Image = image;
        }

        #endregion

        #region Fields
        Image achtergrond;
        int zoompercentage;
        #endregion


    }
}
